﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Skynet_WebBrowser
{
    public partial class Skyweb : Form
    {
        public Skyweb()
        {
            InitializeComponent();
        }

        WebBrowser web = new WebBrowser();
        int wc = 0;
        
        String [] Blacklist = System.IO.File.ReadAllLines("Blacklist.txt");

    
        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void toolStripTextBox1_Click(object sender, EventArgs e)
        {
            adrBarTextBox.SelectAll();
        }

        private void Skyweb_Load(object sender, EventArgs e)
        {
            web = new WebBrowser();
            web.ScriptErrorsSuppressed = true;
            web.Dock = DockStyle.Fill;
            web.Visible = true;
            web.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(web_DocumentCompleted);


            tabControl1.TabPages.Add("New Page");
            tabControl1.SelectTab(wc);
            tabControl1.SelectedTab.Controls.Add(web);
            wc += 1;
               

        }

        void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            tabControl1.SelectedTab.Text = ((WebBrowser)tabControl1.SelectedTab.Controls[0]).DocumentTitle;
            
        }

     
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            web = new WebBrowser();
            web.ScriptErrorsSuppressed = true;
            web.Dock = DockStyle.Fill;
            web.Visible = true;
            web.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(web_DocumentCompleted);


            tabControl1.TabPages.Add("New Page");
            tabControl1.SelectTab(wc);
            tabControl1.SelectedTab.Controls.Add(web);
            wc += 1;
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //if (Ffilter.Checked == false)
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate(adrBarTextBox.Text);
                if (!adrBarTextBox.Items.Contains(adrBarTextBox))
                {
                    adrBarTextBox.Items.Add(adrBarTextBox);
                }
                /*if (Ffilter.Checked == true)
                    foreach (String reject in Blacklist)
                    {
                        if (((WebBrowser)tabControl1.SelectedTab.Controls[0]).DocumentText.Contains(reject))
                        {
                            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Stop();
                            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://test.contempt.ws:8080/reject.html");
                        }

                    }
                 */

         }


        private void adrBarTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                e.SuppressKeyPress = true;

            //if (Ffilter.Checked == false)
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate(adrBarTextBox.Text);
            if (!adrBarTextBox.Items.Contains(adrBarTextBox))
            {
                adrBarTextBox.Items.Add(adrBarTextBox);
            }
            /*if (Ffilter.Checked == true)
                foreach (String reject in Blacklist)
                {
                    if (((WebBrowser)tabControl1.SelectedTab.Controls[0]).DocumentText.Contains(reject))
                    {
                        ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Stop();
                        ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://test.contempt.ws:8080/reject.html");
                    }

                }
             */
        }
             

        private void BackButton_Click(object sender, EventArgs e)
        {
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoBack();
        }

        private void ForwardButton_Click(object sender, EventArgs e)
        {
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoForward();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoHome();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (tabControl1.TabPages.Count - 1 > 0)
            {
                tabControl1.TabPages[tabControl1.SelectedIndex].Controls[0].Dispose();
                tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
                tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
                
                wc -= 1;
            }
        }

        private void Google_Click(object sender, EventArgs e)
        {
            Bing.Checked = !Google.Checked;
            Yandex.Checked = !Google.Checked;
            Yahoo.Checked = !Google.Checked;
            Ask.Checked = !Google.Checked;
            
        }

        private void Bing_Click(object sender, EventArgs e)
        {
            Google.Checked = !Bing.Checked;
            Yandex.Checked = !Bing.Checked;
            Yahoo.Checked = !Bing.Checked;
            Ask.Checked = !Bing.Checked;
        }

        private void Yandex_Click(object sender, EventArgs e)
        {
            Google.Checked = !Yandex.Checked;
            Bing.Checked = !Yandex.Checked;
            Yahoo.Checked = !Yandex.Checked;
            Ask.Checked = !Yandex.Checked;
        }

        private void Yahoo_Click(object sender, EventArgs e)
        {
            Google.Checked = !Yahoo.Checked;
            Bing.Checked = !Yahoo.Checked;
            Yandex.Checked = !Yahoo.Checked;
            Ask.Checked = !Yahoo.Checked;

        }

        private void Ask_Click(object sender, EventArgs e)
        {
            Google.Checked = !Ask.Checked;
            Bing.Checked = !Ask.Checked;
            Yandex.Checked = !Ask.Checked;
            Yahoo.Checked = !Ask.Checked;
        }

        private void toolStripTextBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                if (Google.Checked == true)
                    ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://google.com/search?q=" + toolStripTextBox2.Text);
                if (Bing.Checked == true)
                    ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://www.bing.com/search?q=" + toolStripTextBox2.Text);
                if (Yandex.Checked == true)
                    ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://yandex.com.tr/yandsearch?text=" + toolStripTextBox2.Text);
                if (Yahoo.Checked == true)
                    ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://search.yahoo.com/search?q=" + toolStripTextBox2.Text);
                if (Ask.Checked == true)
                    ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate("http://www.ask.com/search?q=" + toolStripTextBox2.Text); 
        }

        private void toolStripTextBox2_Click(object sender, EventArgs e)
        {
            toolStripTextBox2.SelectAll();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            ((WebBrowser)tabControl1.SelectedTab.Controls[0]).Refresh();
        }

        private void web_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
        {
            if (e.CurrentProgress < e.MaximumProgress)
                toolStripProgressBar1.Value = (int)e.CurrentProgress;
            else toolStripProgressBar1.Value = toolStripProgressBar1.Minimum;

        }
        

        private void web_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            this.toolStripStatusLabel1.Text = ((WebBrowser)tabControl1.SelectedTab.Controls[0]).StatusText;

        }

            
        
 
     }
    }